<?php
	require 'membersession.class.php';
	require 'admin/sql.class.php';
	$arr = MemberSessionInfo::checkMemberLogin();
	if (is_null($arr)) {
		$currentMobile = "";
		$currentPassword = "";
		$currentAvatar = "";
		$currentGender = 0;
		$currentUsername = "";
		$currentNickname = "";
	} else {
		$currentMobile = $arr["mobile"];
		$currentPassword = $arr["password"];
		$currentAvatar = $arr["avatar"];
		$currentGender = $arr["gender"];
		$currentUsername = $arr["username"];
		$currentNickname = $arr["nickname"];
	}
?>
<!DOCTYPE html>
<html>
<head>
	<title>列表</title>
	<link rel="stylesheet" type="text/css" href="/mcnews/css/mcnews.css">
</head>
<script type="text/javascript">
	function checkLoginState(needShow, type) {
		var currentType = "registerMaskView";
		var display = "none";
		if (type == 1) {
			currentType = "loginMaskView"
		}

		if (needShow == true) {
			display = "inline";
		}
		document.getElementById(currentType).style.display=display;
	}

	function showLogin() {
		checkLoginState(true, 1);
	}

	function dissmissLogin() {
		checkLoginState(false, 1);
	}

	function showRegister() {
		checkLoginState(true, 0);
	}

	function dissmissRegister() {
		checkLoginState(false, 0);
	}

	function checkPageState(currentPage, allPage) {

		//alert(bbj);
		for (var i = 1; i <= allPage; i++) {
							//if ($i == $currentPage + 1) {
			var key = "clickPage" + (i - 1);
			
			if (i == currentPage + 1) {
				document.getElementById(key).style.backgroundColor = 'gray';
			} else {
				document.getElementById(key).style.backgroundColor = 'white';
			}
		}

		getContentListbb(currentPage);
	}


	// 分页
	function getContentListbb(page) {
		
		//alert(page);
		var xmlhttp;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange = function() {
			
			if (xmlhttp.readyState == 4) {
				var ret = xmlhttp.responseText;

				//alert(ret);
				document.getElementById("contentlist").innerHTML = ret;
			}
		}

		xmlhttp.open("GET", "listaction.php?page=" + page, true);
		xmlhttp.send();
		return false;
	}

	

</script>

<body>

<div class="loginMaskView" id="loginMaskView" onclick="dissmissLogin();">
	<div class="loginSubView">
		<iframe class="loginView" src="login.php" frameborder="0"></iframe>
	</div>
</div>

<div class="loginMaskView" id="registerMaskView" onclick="dissmissRegister();">
	<div class="loginSubView">
		<iframe class="loginView" src="register.php" frameborder="0"></iframe>
	</div>
</div>

<div class="header">
	<?php 
		$h = "";
		if (empty($currentMobile)) {
			$h = "<div class='rightbutton'>
					<a onclick='showLogin();'>登录</a>
					<a onclick='showRegister();'>注册</a>
				</div>";
		} else {
			$h = "<div class='rightbutton'>
					<img src='" . $currentAvatar . "'>
					<a>" . $currentMobile . "</a>
					<a href='outlogin.php'>退出</a>
				</div>";
		}
		echo $h;
	?>	
</div>

<div class="divbody">
	<!--导航栏-->
	<div class="nav">
     <ul>
       <li><a href="index.php">首页</a></li>
       <li><a href="#">文章</a></li>
       <li><a href="#">故事</a></li>
       <li><a href="#">散文</a></li>
       <li><a href="#">诗歌</a></li>
       <li><a href="#">日记</a></li>
       <li><a href="#">小说</a></li>
      </ul>
	</div>

	<!-- 内容 -->
	<div class="content">
		<div class="leftList">
			<ul id="contentlist">
				<!-- <?php 
					$currentPage = 0;
					$currentPage = $_GET["page"];
					$arr = getListFromContent($currentPage * 3, 3);
					foreach ($arr as $key => $value) {
						echo "<li>
								<div><a href='#'><strong>[" . $value["classname"] . "]</strong></a><a href='#'><strong>" . $value["title"] . "</strong></a></div>
								<p>" . $value["content"] . "</p>
								<span>日期：" . $value["createTime"] . " 点击：1748 作者：" . $value["nickname"] . "</span>
							</li>";
					}
				?> -->
				
			</ul>
			<div class="page">
					<?php
						$ret = getCountFromContent();
						
						// 每页显示3条数据,
						$row = 3;
						if ($ret < $row) {
							// 总数<row, 只有1页
							$page = 1;
						} else {
							$page = $ret / $row;

							if ($page > (int)$page) {
								// 10 / 3 = 3.33 
								// 3.33 > 3 有4页
								$page += 1;
							}
						}

						for ($i = 1; $i <= $page; $i++) {
							//if ($i == $currentPage + 1) {
								// echo "<a href='list.php?type=2&page=" . ($i-1) . "' class='current'>" . $i . "</a>";
							//	echo "<a href='#' class='current' onclick='getContentListbb($i-1)'>" . $i . "</a>";
							//} else {
								// echo "<a href='list.php?type=2&page=" . ($i-1) . "'>" . $i . "</a>";
								echo "<a id='clickPage" . ($i-1) . "' href='#' onclick='checkPageState($i-1, $page)'>" . $i . "</a>";
							//}
						}

					?>
				</div>
		</div>
		<div class="rightList">
		
		</div>
	</div>
	<script type='text/javascript'>
		document.getElementById("clickPage0").click();
	</script>
</div>

</body>
</html>